﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebDulich.Models;
using WebDulich.Repository;
using WebDulich.Repository.Dapper;

namespace WebDulich.Controllers
{
    public class CategoryController : ApiController
    {
        SqlRepository _repository = new SqlRepository();
        
        [Route("api/category/getlist/{pindex}/{psize}")]
        [HttpGet]
        public List<Category> Get(int pindex, int psize)
        {
            return _repository.Categories.GetAll(pindex, psize, true);
        }

        [Route("api/category/get/{id}")]
        [HttpGet]
        public Category Get(int id)
        {
            return _repository.Categories.Get(id.ToString());
        }

        [Route("api/category/add")]
        [HttpPost]
        public Category Add(Category cat)
        {
            return _repository.Categories.Insert(cat);
        }

        [Route("api/category/update/{id}")]
        [HttpPut]
        public bool Put(int id, Category cat)
        {
            cat.Id = id;
            return _repository.Categories.Update(cat);
        }

        [Route("api/category/delete/{id}")]
        [HttpDelete]
        public bool Delete(int id)
        {
            return _repository.Categories.Remove(id.ToString());
        }
    }
}
